import { Component, OnInit } from '@angular/core';
import * as $ from 'jquery';
import {Router} from '@angular/router';
import {MessageService} from '../../services/message.service';
import {LoginService} from "../../services/login.service";
import {ExitService} from "../../services/exit.service";
import {AppComponent} from "../../app.component";
import {HttpClient} from '@angular/common/http';
@Component({
  selector: 'app-my-header',
  templateUrl: './my-header.component.html',
  styleUrls: ['./my-header.component.css']
})
export class MyHeaderComponent implements OnInit {
  //

  ojbk = '';
  loginStr = '登录';
  registerStr = '注册';
  isDisplay = true;
  isfat: true;
  aStr: string;
  hot = [
    '奇异果',
    '牛油果',
    '山竹',
    '牛排'
  ];
  // 搜索到的商品
  anyproduct: any;
  constructor(private router: Router, private msg: MessageService, private lg: LoginService, private app: AppComponent, private http: HttpClient) {

  }
  ngOnInit() {
    this.lg.getMess().subscribe((data) => {
      this.loginStr = data['login'];
      this.registerStr = data['exit'];
    });
  }
  doClick() {
    if (this.registerStr === '注册') {
      this.router.navigate(['/register']);
      this.isDisplay = false;
      $('#wrapper').attr('height', '166px');
      this.aStr = '会员注册';
      $('#aStr').css({'borderLeft': '1px solid rgb(206,206,206)'});
    } else {
      this.router.navigate(['/login']);
      this.loginStr = '登录';
      this.registerStr = '注册';
      this.lg.str = '登录';
    }
  }
  login() {
    if (this.loginStr === '登录') {
      this.router.navigate(['/login']);
      this.isDisplay = false;
      $('#wrapper').attr('height', '166px');
      this.aStr = '会员登录';
      $('#aStr').css({'borderLeft': '1px solid rgb(206,206,206)'});
    } else {
      this.router.navigate(['/myOrder/account']);
    }
  }
  doPath() {
    // 引入路由重定向
    this.router.navigate(['/myOrder/account']);
  }
  doCar() {
    this.router.navigate(['/car']);
  }
  // 我的订单点击
  doOrder() {
    if (this.loginStr === '登录') {
      this.router.navigate(['/login']);
    } else {
      this.router.navigate(['/myOrder/order']);
    }
  }
  // 点击我的消息
  doNew() {
    if (this.loginStr === '登录') {
      this.router.navigate(['/login']);
    } else {
      this.router.navigate(['/myOrder/new']);
    }
  }
  // 商品总数
  aszong () {
    return this.app.getToalCount();
  }
  // 搜索框
  // dosousuo () {
  //   this.http.post('', {
  //     depict: this.ojbk
  //   }).subscribe((data) => {
  //     this.anyproduct = data;
  //   });
  // }
  // 点击搜索按钮
  clicsou () {
    this.http.post('', {
      depict: this.ojbk
    }).subscribe((data) => {
      this.anyproduct = data;
    });
    this.router.navigate(['/sousuo', this.anyproduct.imgs, this.anyproduct.depict, this.anyproduct.sprice]);
  }
}
